home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 10 / AACD 10.iso / AACD / Games / MAME / src / vidhrdw / arabian.c < prev    next >
C/C++ Source or Header  |  2000-04-04  |  11KB  |  447 lines

  1. /***************************************************************************
  2.  
  3.   vidhrdw.c
  4.  
  5.   Functions to emulate the video hardware of the machine.
  6.  
  7. ***************************************************************************/
  8.  
  9. #include "driver.h"
  10. #include "vidhrdw/generic.h"
  11.  
  12.  
  13.  
  14. static struct osd_bitmap *tmpbitmap2;
  15. static unsigned char inverse_palette[256]; /* JB 970727 */
  16.  
  17.  
  18. void arabian_vh_convert_color_prom(unsigned char *palette, unsigned short *colortable,const unsigned char *color_prom)
  19. {
  20.     int i;
  21.  
  22.     /* this should be very close */
  23.     for (i = 0;i < Machine->drv->total_colors/2;i++)
  24.     {
  25.         int on;
  26.  
  27.  
  28.         on = (i & 0x08) ? 0x80 : 0xff;
  29.  
  30.         *(palette++) = (i & 0x04) ? 0xff : 0;
  31.         *(palette++) = (i & 0x02) ? on : 0;
  32.         *(palette++) = (i & 0x01) ? on : 0;
  33.     }
  34.  
  35.  
  36.     /* this is handmade to match the screen shot */
  37.  
  38.     *(palette++) = 0x00;
  39.     *(palette++) = 0x00;      // 0000
  40.     *(palette++) = 0x00;
  41.  
  42.     *(palette++) = 0x00;
  43.     *(palette++) = 0xff;  // 0001
  44.     *(palette++) = 0x00;
  45.  
  46.     *(palette++) = 0x00;
  47.     *(palette++) = 0xff;  // 0010
  48.     *(palette++) = 0x00;
  49.  
  50.     *(palette++) = 0x00;
  51.     *(palette++) = 0xff;  // 0011
  52.     *(palette++) = 0x00;
  53.  
  54.     *(palette++) = 0xff;
  55.     *(palette++) = 0x00;  // 0100
  56.     *(palette++) = 0x00;
  57.  
  58.     *(palette++) = 0xff;
  59.     *(palette++) = 0xff;  // 0101
  60.     *(palette++) = 0x00;
  61.  
  62.     *(palette++) = 0xff;
  63.     *(palette++) = 0xff;  // 0110
  64.     *(palette++) = 0x00;
  65.  
  66.     *(palette++) = 0xff;
  67.     *(palette++) = 0xff;  // 0111
  68.     *(palette++) = 0x00;
  69.  
  70.  
  71.  
  72.     *(palette++) = 0x00;
  73.     *(palette++) = 0x00;  // 1000
  74.     *(palette++) = 0x00;
  75.  
  76.     *(palette++) = 0xff;
  77.     *(palette++) = 0xff;  // 1001
  78.     *(palette++) = 0x00;
  79.  
  80.     *(palette++) = 0xff;
  81.     *(palette++) = 0x80;  // 1010
  82.     *(palette++) = 0x00;
  83.  
  84.     *(palette++) = 0x00;
  85.     *(palette++) = 0xff;  // 1011
  86.     *(palette++) = 0x00;
  87.  
  88.     *(palette++) = 0xff;
  89.     *(palette++) = 0x00;  // 1100
  90.     *(palette++) = 0x00;
  91.  
  92.     *(palette++) = 0xff;
  93.     *(palette++) = 0xff;  // 1101
  94.     *(palette++) = 0x00;
  95.  
  96.     *(palette++) = 0xff;
  97.     *(palette++) = 0x80;  // 1110
  98.     *(palette++) = 0x00;
  99.  
  100.     *(palette++) = 0xff;
  101.     *(palette++) = 0xff;  // 1111
  102.     *(palette++) = 0x00;
  103. }
  104.  
  105. /***************************************************************************
  106.  
  107.   Draw the game screen in the given osd_bitmap.
  108.   Do NOT call osd_update_display() from this function, it will be called by
  109.   the main emulation engine.
  110.  
  111. ***************************************************************************/
  112.  
  113. int arabian_vh_start(void)
  114. {
  115.     int p1,p2,p3,p4,v1,v2,offs;
  116.     int i;    /* JB 970727 */
  117.  
  118.     if ((tmpbitmap = osd_create_bitmap(Machine->drv->screen_width,Machine->drv->screen_height)) == 0)
  119.         return 1;
  120.  
  121.     if ((tmpbitmap2 = osd_create_bitmap(Machine->drv->screen_width,Machine->drv->screen_height)) == 0)
  122.     {
  123.         osd_free_bitmap(tmpbitmap2);
  124.         return 1;
  125.     }
  126.  
  127.     /* JB 970727 */
  128.     for (i = 0;i < Machine->drv->total_colors;i++)
  129.         inverse_palette[ Machine->pens[i] ] = i;
  130.  
  131. /*transform graphics data into more usable format*/
  132. /*which is coded like this:
  133.  
  134.   byte adr+0x4000  byte adr
  135.   DCBA DCBA        DCBA DCBA
  136.  
  137. D-bits of pixel 4
  138. C-bits of pixel 3
  139. B-bits of pixel 2
  140. A-bits of pixel 1
  141.  
  142. after conversion :
  143.  
  144.   byte adr+0x4000  byte adr
  145.   DDDD CCCC        BBBB AAAA
  146. */
  147.  
  148.   for (offs=0; offs<0x4000; offs++)
  149.   {
  150.      v1 = memory_region(REGION_GFX1)[offs];
  151.      v2 = memory_region(REGION_GFX1)[offs+0x4000];
  152.  
  153.      p1 = (v1 & 0x01) | ( (v1 & 0x10) >> 3) | ( (v2 & 0x01) << 2 ) | ( (v2 & 0x10) >> 1);
  154.      v1 = v1 >> 1;
  155.      v2 = v2 >> 1;
  156.      p2 = (v1 & 0x01) | ( (v1 & 0x10) >> 3) | ( (v2 & 0x01) << 2 ) | ( (v2 & 0x10) >> 1);
  157.      v1 = v1 >> 1;
  158.      v2 = v2 >> 1;
  159.      p3 = (v1 & 0x01) | ( (v1 & 0x10) >> 3) | ( (v2 & 0x01) << 2 ) | ( (v2 & 0x10) >> 1);
  160.      v1 = v1 >> 1;
  161.      v2 = v2 >> 1;
  162.      p4 = (v1 & 0x01) | ( (v1 & 0x10) >> 3) | ( (v2 & 0x01) << 2 ) | ( (v2 & 0x10) >> 1);
  163.  
  164.      memory_region(REGION_GFX1)[offs] = p1 | (p2<<4);
  165.      memory_region(REGION_GFX1)[offs+0x4000] = p3 | (p4<<4);
  166.  
  167.   }
  168.     return 0;
  169. }
  170.  
  171. /***************************************************************************
  172.  
  173.   Stop the video hardware emulation.
  174.  
  175. ***************************************************************************/
  176.  
  177. void arabian_vh_stop(void)
  178. {
  179.     osd_free_bitmap(tmpbitmap2);
  180.     osd_free_bitmap(tmpbitmap);
  181. }
  182.  
  183.  
  184.  
  185.  
  186. INLINE void blit_byte(UINT8 x, UINT8 y, int val, int val2, UINT8 plane)
  187. {
  188.     int p1,p2,p3,p4;
  189.  
  190.     INT8 dx=1,dy=0;
  191.  
  192.  
  193.     p4 =  val        & 0x0f;
  194.     p3 = (val  >> 4) & 0x0f;
  195.     p2 =  val2       & 0x0f;
  196.     p1 = (val2 >> 4) & 0x0f;
  197.  
  198.  
  199.     if (Machine->orientation & ORIENTATION_SWAP_XY)
  200.     {
  201.         int t;
  202.  
  203.         t = x; x = y; y = t;
  204.         t = dx; dx = dy; dy = t;
  205.     }
  206.     if (Machine->orientation & ORIENTATION_FLIP_X)
  207.     {
  208.         x = x ^ 0xff;
  209.         dx = -dx;
  210.     }
  211.     if (Machine->orientation & ORIENTATION_FLIP_Y)
  212.     {
  213.         y = y ^ 0xff;
  214.         dy = -dy;
  215.     }
  216.  
  217.  
  218.     if (plane & 0x01)
  219.     {
  220.         if (p4 != 8)  tmpbitmap ->line[y     ][x     ] = Machine->pens[p4];
  221.         if (p3 != 8)  tmpbitmap ->line[y+  dy][x+  dx] = Machine->pens[p3];
  222.         if (p2 != 8)  tmpbitmap ->line[y+2*dy][x+2*dx] = Machine->pens[p2];
  223.         if (p1 != 8)  tmpbitmap ->line[y+3*dy][x+3*dx] = Machine->pens[p1];
  224.     }
  225.  
  226.     if (plane & 0x04)
  227.     {
  228.         if (p4 != 8)  tmpbitmap2->line[y     ][x     ] = Machine->pens[16+p4];
  229.         if (p3 != 8)  tmpbitmap2->line[y+  dy][x+  dx] = Machine->pens[16+p3];
  230.         if (p2 != 8)  tmpbitmap2->line[y+2*dy][x+2*dx] = Machine->pens[16+p2];
  231.         if (p1 != 8)  tmpbitmap2->line[y+3*dy][x+3*dx] = Machine->pens[16+p1];
  232.     }
  233.  
  234.     if (dx >= 0 && dy >= 0)
  235.         osd_mark_dirty(x,y,x+3*dx,y+3*dy,0);
  236.     else if (dx >= 0)
  237.         osd_mark_dirty(x,y+3*dy,x+3*dx,y,0);
  238.     else if (dy >= 0)
  239.         osd_mark_dirty(x+3*dx,y,x,y+3*dy,0);
  240.     else
  241.         osd_mark_dirty(x+3*dx,y+3*dy,x,y,0);
  242. }
  243.  
  244.  
  245. void arabian_blit_area(UINT8 plane, UINT16 src, UINT8 x, UINT8 y, UINT8 sx, UINT8 sy)
  246. {
  247.     int i,j;
  248.  
  249.     for (i = 0; i <= sx; i++, x += 4)
  250.     {
  251.         for (j = 0; j <= sy; j++)
  252.         {
  253.             blit_byte(x, y+j, memory_region(REGION_GFX1)[src], memory_region(REGION_GFX1)[src+0x4000], plane);
  254.             src++;
  255.         }
  256.     }
  257. }
  258.  
  259.  
  260. WRITE_HANDLER( arabian_blitter_w )
  261. {
  262.     spriteram[offset] = data;
  263.  
  264.     if ((offset & 0x07) == 6)
  265.     {
  266.         UINT8 plane,x,y,sx,sy;
  267.         UINT16 src;
  268.  
  269.         plane = spriteram[offset-6];
  270.         src   = spriteram[offset-5] | (spriteram[offset-4] << 8);
  271.         x     = spriteram[offset-2] << 2;
  272.         y     = spriteram[offset-3];
  273.         sx    = spriteram[offset-0];
  274.         sy    = spriteram[offset-1];
  275.  
  276.         arabian_blit_area(plane,src,x,y,sx,sy);
  277.     }
  278. }
  279.  
  280.  
  281.  
  282. WRITE_HANDLER( arabian_videoram_w )
  283. {
  284.     int plane1,plane2,plane3,plane4;
  285.     unsigned char *bm;
  286.  
  287.     UINT8 x,y;
  288.     INT8 dx=1, dy=0;
  289.  
  290.  
  291.     plane1 = spriteram[0] & 0x01;
  292.     plane2 = spriteram[0] & 0x02;
  293.     plane3 = spriteram[0] & 0x04;
  294.     plane4 = spriteram[0] & 0x08;
  295.  
  296.     x = (offset >> 8) << 2;
  297.     y = offset & 0xff;
  298.  
  299.  
  300.     if (Machine->orientation & ORIENTATION_SWAP_XY)
  301.     {
  302.         int t;
  303.  
  304.         t = x; x = y; y = t;
  305.         t = dx; dx = dy; dy = t;
  306.     }
  307.     if (Machine->orientation & ORIENTATION_FLIP_X)
  308.     {
  309.         x = x ^ 0xff;
  310.         dx = -dx;
  311.     }
  312.     if (Machine->orientation & ORIENTATION_FLIP_Y)
  313.     {
  314.         y = y ^ 0xff;
  315.         dy = -dy;
  316.     }
  317.  
  318.  
  319.     /* JB 970727 */
  320.     tmpbitmap ->line[y     ][x     ] = inverse_palette[ tmpbitmap ->line[y     ][x     ] ];
  321.     tmpbitmap ->line[y+  dy][x+  dx] = inverse_palette[ tmpbitmap ->line[y+  dy][x+  dx] ];
  322.     tmpbitmap ->line[y+2*dy][x+2*dx] = inverse_palette[ tmpbitmap ->line[y+2*dy][x+2*dx] ];
  323.     tmpbitmap ->line[y+3*dy][x+3*dx] = inverse_palette[ tmpbitmap ->line[y+3*dy][x+3*dx] ];
  324.     tmpbitmap2->line[y     ][x     ] = inverse_palette[ tmpbitmap2->line[y     ][x     ] ];
  325.     tmpbitmap2->line[y+  dy][x+  dx] = inverse_palette[ tmpbitmap2->line[y+  dy][x+  dx] ];
  326.     tmpbitmap2->line[y+2*dy][x+2*dx] = inverse_palette[ tmpbitmap2->line[y+2*dy][x+2*dx] ];
  327.     tmpbitmap2->line[y+3*dy][x+3*dx] = inverse_palette[ tmpbitmap2->line[y+3*dy][x+3*dx] ];
  328.  
  329.     if (plane1)
  330.     {
  331.         bm = &tmpbitmap->line[y     ][x     ];
  332.         *bm &= 0xf3;
  333.         if (data & 0x10) *bm |= 8;
  334.         if (data & 0x01) *bm |= 4;
  335.  
  336.         bm = &tmpbitmap->line[y+  dy][x+  dx];
  337.         *bm &= 0xf3;
  338.         if (data & 0x20) *bm |= 8;
  339.         if (data & 0x02) *bm |= 4;
  340.  
  341.         bm = &tmpbitmap->line[y+2*dy][x+2*dx];
  342.         *bm &= 0xf3;
  343.         if (data & 0x40) *bm |= 8;
  344.         if (data & 0x04) *bm |= 4;
  345.  
  346.         bm = &tmpbitmap->line[y+3*dy][x+3*dx];
  347.         *bm &= 0xf3;
  348.         if (data & 0x80) *bm |= 8;
  349.         if (data & 0x08) *bm |= 4;
  350.     }
  351.  
  352.     if (plane2)
  353.     {
  354.         bm = &tmpbitmap->line[y     ][x     ];
  355.         *bm &= 0xfc;
  356.         if (data & 0x10) *bm |= 2;
  357.         if (data & 0x01) *bm |= 1;
  358.  
  359.         bm = &tmpbitmap->line[y+  dy][x+  dx];
  360.         *bm &= 0xfc;
  361.         if (data & 0x20) *bm |= 2;
  362.         if (data & 0x02) *bm |= 1;
  363.  
  364.         bm = &tmpbitmap->line[y+2*dy][x+2*dx];
  365.         *bm &= 0xfc;
  366.         if (data & 0x40) *bm |= 2;
  367.         if (data & 0x04) *bm |= 1;
  368.  
  369.         bm = &tmpbitmap->line[y+3*dy][x+3*dx];
  370.         *bm &= 0xfc;
  371.         if (data & 0x80) *bm |= 2;
  372.         if (data & 0x08) *bm |= 1;
  373.     }
  374.  
  375.     if (plane3)
  376.     {
  377.         bm = &tmpbitmap2->line[y     ][x     ];
  378.         *bm &= 0xf3;
  379.         if (data & 0x10) *bm |= (16+8);
  380.         if (data & 0x01) *bm |= (16+4);
  381.  
  382.         bm = &tmpbitmap2->line[y+  dy][x+  dx];
  383.         *bm &= 0xf3;
  384.         if (data & 0x20) *bm |= (16+8);
  385.         if (data & 0x02) *bm |= (16+4);
  386.  
  387.         bm = &tmpbitmap2->line[y+2*dy][x+2*dx];
  388.         *bm &= 0xf3;
  389.         if (data & 0x40) *bm |= (16+8);
  390.         if (data & 0x04) *bm |= (16+4);
  391.  
  392.         bm = &tmpbitmap2->line[y+3*dy][x+3*dx];
  393.         *bm &= 0xf3;
  394.         if (data & 0x80) *bm |= (16+8);
  395.         if (data & 0x08) *bm |= (16+4);
  396.     }
  397.  
  398.     if (plane4)
  399.     {
  400.         bm = &tmpbitmap2->line[y     ][x     ];
  401.         *bm &= 0xfc;
  402.         if (data & 0x10) *bm |= (16+2);
  403.         if (data & 0x01) *bm |= (16+1);
  404.  
  405.         bm = &tmpbitmap2->line[y+  dy][x+  dx];
  406.         *bm &= 0xfc;
  407.         if (data & 0x20) *bm |= (16+2);
  408.         if (data & 0x02) *bm |= (16+1);
  409.  
  410.         bm = &tmpbitmap2->line[y+2*dy][x+2*dx];
  411.         *bm &= 0xfc;
  412.         if (data & 0x40) *bm |= (16+2);
  413.         if (data & 0x04) *bm |= (16+1);
  414.  
  415.         bm = &tmpbitmap2->line[y+3*dy][x+3*dx];
  416.         *bm &= 0xfc;
  417.         if (data & 0x80) *bm |= (16+2);
  418.         if (data & 0x08) *bm |= (16+1);
  419.     }
  420.  
  421.     /* JB 970727 */
  422.     tmpbitmap ->line[y     ][x     ] = Machine->pens[ tmpbitmap ->line[y     ][x     ] ];
  423.     tmpbitmap ->line[y+  dy][x+  dx] = Machine->pens[ tmpbitmap ->line[y+  dy][x+  dx] ];
  424.     tmpbitmap ->line[y+2*dy][x+2*dx] = Machine->pens[ tmpbitmap ->line[y+2*dy][x+2*dx] ];
  425.     tmpbitmap ->line[y+3*dy][x+3*dx] = Machine->pens[ tmpbitmap ->line[y+3*dy][x+3*dx] ];
  426.     tmpbitmap2->line[y     ][x     ] = Machine->pens[ tmpbitmap2->line[y     ][x     ] ];
  427.     tmpbitmap2->line[y+  dy][x+  dx] = Machine->pens[ tmpbitmap2->line[y+  dy][x+  dx] ];
  428.     tmpbitmap2->line[y+2*dy][x+2*dx] = Machine->pens[ tmpbitmap2->line[y+2*dy][x+2*dx] ];
  429.     tmpbitmap2->line[y+3*dy][x+3*dx] = Machine->pens[ tmpbitmap2->line[y+3*dy][x+3*dx] ];
  430.  
  431.     if (dx >= 0 && dy >= 0)
  432.         osd_mark_dirty(x,y,x+3*dx,y+3*dy,0);
  433.     else if (dx >= 0)
  434.         osd_mark_dirty(x,y+3*dy,x+3*dx,y,0);
  435.     else if (dy >= 0)
  436.         osd_mark_dirty(x+3*dx,y,x,y+3*dy,0);
  437.     else
  438.         osd_mark_dirty(x+3*dx,y+3*dy,x,y,0);
  439. }
  440.  
  441.  
  442. void arabian_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
  443. {
  444.     copybitmap(bitmap,tmpbitmap2,0,0,0,0,&Machine->drv->visible_area,TRANSPARENCY_NONE, 0);
  445.      copybitmap(bitmap,tmpbitmap ,0,0,0,0,&Machine->drv->visible_area,TRANSPARENCY_COLOR,0);
  446. }
  447.